#ifndef UR_MANUAL_H_
#define UR_MANUAL_H_

// Default data boundaries
#define UR_MANUAL_PWM_MIN 1000
#define UR_MANUAL_PWM_MAX 2000
#define UR_MANUAL_SRV_MIN 0
#define UR_MANUAL_SRV_MAX 4000

#include "AbstractData.h"
/*
 * class URManual
 * 
 * Represents manual conrtol data
 *
 *
 * MANUAL               min         max  bytes  + comma    unit  data type
 * -----------------------------------------------------------------------
 * PWM1     	       1000        2000
 * PWM2     	       1000        2000
 * PWM3     	       1000        2000
 * SRV1                   0        4000
 * SRV2                   0        4000
 * -----------------------------------------------------------------------
 */
class URManual : public AbstractData
{
private:
    // Data members
	float m_PWM1;
	float m_PWM2;
	float m_PWM3;
	float m_Srv1;
	float m_Srv2;

    // Data handling
    int SerializeSentence(std::stringstream& stream, const bool& isSending)
    {
        // Call base class serialization
        AbstractData::SerializeSentence(stream, isSending);

        if (isSending)
        {
            // Send data to stream
            stream << std::setprecision(2) << m_PWM1 << ',';
            stream << std::setprecision(2) << m_PWM2 << ',';
            stream << std::setprecision(2) << m_PWM3 << ',';
            stream << std::setprecision(2) << m_Srv1 << ',';
            stream << std::setprecision(2) << m_Srv2;
        }
        else
        {
            char comma;
            float pwm1, pwm2, pwm3;
            float srv1, srv2;
       
            // Receive data from stream
            stream >> pwm1 >> comma;
            stream >> pwm2 >> comma;
            stream >> pwm3 >> comma;
            stream >> srv1 >> comma;
            stream >> srv2;

            // Set the values
            SetPWM1(pwm1);
            SetPWM2(pwm2);
            SetPWM3(pwm3);
            SetSrv1(srv1);
            SetSrv2(srv2);
        }

        return 0;
    }

public:

    // Constructor
    URManual() : AbstractData("URMAN"),
    m_PWM1(1000), m_PWM2(1000), m_PWM3(1000), m_Srv1(2000), m_Srv2(2000)
    {}
    
    // Get
    inline const float& GetPWM1() { return m_PWM1; }
    inline const float& GetPWM2() { return m_PWM2; }
    inline const float& GetPWM3() { return m_PWM3; }
    inline const float& GetSrv1() { return m_Srv1; }
    inline const float& GetSrv2() { return m_Srv2; }

    // Set
    int SetPWM1(const float& value)
    {
        if (value > UR_MANUAL_PWM_MAX)
        {
        	m_PWM1 = UR_MANUAL_PWM_MAX;
            return 666;
        }
        else if (value < UR_MANUAL_PWM_MIN)
        {
        	m_PWM1 = UR_MANUAL_PWM_MIN;
            return -666;
        }
 
        m_PWM1 = value;
        return 0;
    }

    int SetPWM2(const float& value)
	{
		if (value > UR_MANUAL_PWM_MAX)
		{
			m_PWM2 = UR_MANUAL_PWM_MAX;
			return 666;
		}
		else if (value < UR_MANUAL_PWM_MIN)
		{
			m_PWM2 = UR_MANUAL_PWM_MIN;
			return -666;
		}

		m_PWM2 = value;
		return 0;
	}

    int SetPWM3(const float& value)
	{
		if (value > UR_MANUAL_PWM_MAX)
		{
			m_PWM3 = UR_MANUAL_PWM_MAX;
			return 666;
		}
		else if (value < UR_MANUAL_PWM_MIN)
		{
			m_PWM3 = UR_MANUAL_PWM_MIN;
			return -666;
		}

		m_PWM3 = value;
		return 0;
	}

    int SetSrv1(const float& value)
	{
		if (value > UR_MANUAL_SRV_MAX)
		{
			m_Srv1 = UR_MANUAL_SRV_MAX;
			return 666;
		}
		else if (value < UR_MANUAL_SRV_MIN)
		{
			m_Srv1 = UR_MANUAL_SRV_MIN;
			return -666;
		}

		m_Srv1 = value;
		return 0;
	}

    int SetSrv2(const float& value)
	{
		if (value > UR_MANUAL_SRV_MAX)
		{
			m_Srv2 = UR_MANUAL_SRV_MAX;
			return 666;
		}
		else if (value < UR_MANUAL_SRV_MIN)
		{
			m_Srv2 = UR_MANUAL_SRV_MIN;
			return -666;
		}
 
		m_Srv2 = value;
		return 0;
	}
};

#endif /* UR_MANUAL_H_ */
